package com.wysql.iostream;

import java.io.*;
import java.util.ArrayList;

public class ObjectStream {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student student1 = new Student("1","zhangsan",19);
        Student student2 = new Student("2","lisi",20);
        ArrayList<Student> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("IOstream/src/filebook/stu.txt"));
        objectOutputStream.writeObject(list);
        objectOutputStream.close();

        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("IOstream/src/filebook/stu.txt"));
        Object obj = null;
        Student o = null;
        ArrayList<Student> list2 = (ArrayList<Student>) objectInputStream.readObject();
        for (Student student : list2) {
            System.out.println(student);
        }
        objectInputStream.close();
    }
}
